#include<bits/stdc++.h>
using namespace std;
namespace IO{
    char buff[1<<21],*p1=buff,*p2=buff;
    char getch(){
        return p1==p2&&(p2=((p1=buff)+fread(buff,1,1<<21,stdin)),p1==p2)?EOF:*p1++;
    }
    template<typename T>
    void read(T &x){
        char ch=getch();int fl=1;x=0;
        while(ch>'9'||ch<'0'){if(ch=='-')fl=-1;ch=getch();}
        while(ch<='9'&&ch>='0'){x=x*10+ch-48;ch=getch();}
        x*=fl;
    }
    template<typename T,typename ...Args>
    void read(T &x,Args& ...args){
        read(x);read(args...);
    }
    char obuf[1<<21],*p3=obuf;
    void putch(char ch){
        if(p3-obuf<(1<<21))*p3++=ch;
        else fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=ch;
    }
    char ch[100];
    template<typename T>
    void write(T x){
        if(!x)return putch('0');
        if(x<0)putch('-'),x*=-1;
        int top=0;
        while(x)ch[++top]=x%10+48,x/=10;
        while(top)putch(ch[top]),top--;
    }
    template<typename T,typename ...Args>
    void write(T x,Args ...args){
        write(x);write(args...);
    }
    void flush(){fwrite(obuf,p3-obuf,1,stdout);}
}
using namespace IO;
const int N=3e5+5;
int n,q;
int l[N],r[N];
signed main(){
	freopen("study.in","r",stdin);
	freopen("study.out","w",stdout);
	read(n,q);
	for(int i=1;i<n;i++)read(l[i],r[i]),r[i]--;
	while(q--){
		int ops;
		read(ops);
		if(ops==1){
			int p;
			read(p);
			read(l[p],r[p]),r[p]--;
		}else{
			int a,now,c,d,ans=0;
			read(a,now,c,d);
			if(a<=c){
				while(a<c){
					if(now>r[a]){
						ans+=now-r[a];
						now=r[a];
					}
					if(now<l[a])now=l[a];
					now++;
					a++;
				}
			}else{
				while(a>c){
					if(now>r[a-1]){
						ans+=now-r[a-1];
						now=r[a-1];
					}
					if(now<l[a-1])now=l[a-1];
					now++;
					a--;
				}
			}
			if(now>d)ans+=now-d;
			write(ans),putch('\n');
		}
	}
	flush();
	return 0;
}
